import {Component, Injectable, ModuleWithProviders, NgModule} from '@angular/core';
import {NzModalRef, NzModalService} from 'ng-zorro-antd/modal';


@Injectable()
export class LoadingService {

  constructor(private modalService: NzModalService) {
  }

  open(): NzModalRef {
    return this.modalService.info({nzContent: LoadingComponent});
    // return this.modalService.open(LoadingComponent, {backdrop: 'static'});
  }

  close(modalRef: NzModalRef): void {
    modalRef.close();
  }

}

@Component({
  template: `
    <div class="p-1"><i class="fa fa-2x fa-spinner text-primary" aria-hidden="true"></i> &nbsp;处理中。。。</div>`,
  styles: [`
    @-webkit-keyframes spin {
      from {
        -webkit-transform: rotate(0deg);
      }
      to {
        -webkit-transform: rotate(360deg);
      }
    }

    @keyframes spin {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }

    .fa-spinner {
      -webkit-animation: spin 1s linear 1s 5 alternate;
      animation: spin 1s linear infinite;
    }
  `]
})
export class LoadingComponent {
}

@NgModule({
  declarations: [LoadingComponent],
  entryComponents: [LoadingComponent],
  exports: [LoadingComponent],
  providers: [LoadingService]
})
export class LoadingModel {
  static forRoot(): ModuleWithProviders<any> {
    return {
      ngModule: LoadingModel,
      providers: [LoadingService]
    };
  }
}
